home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / bin / qt20fix.z / qt20fix
Text File  |  2002-04-08  |  8KB  |  260 lines

  1. #!/usr/bin/perl -w
  2. #
  3. # in sh/bash/zsh:
  4. #    make 2>&1 | .../qt/bin/qt20fix
  5. # in csh/tcsh
  6. #    make |& .../qt/bin/qt20fix
  7. #
  8. # repeat as long as qt20fix says to.  if your make supports the -k
  9. # flag, that speeds up the process a bit.
  10. #
  11. # qt20fix tends to fix a bit over half of the remaining problems in
  12. # each run.
  13. #
  14. # if you don't use gcc, you will need to change parseline.
  15. #
  16.  
  17.  
  18. # this function must accept one line, which is presumed to be an error
  19. # message, and return an array of three strings: the file name, the
  20. # line number and the variable that is undefined.
  21. #
  22. # it may also return an empty list, if the line isn't an error message.
  23. #
  24. # the function is called on each line in turn and only once on each
  25. # line, so it's possible to save state.
  26. #
  27.  
  28. sub parseline{
  29.     my( $line ) = @_;
  30.  
  31.     chomp $line;
  32.  
  33.     if ( $line =~ m%^([-a-zA-Z0-9_\./]+\.[a-zA-Z]+):(\d+):\s*\`(.+)\' undeclared% ) {
  34.     @r = ($1,$2,$3);
  35.     $r[0] = $currentdir . $r[0] if ( defined($currentdir) &&
  36.                      $r[0] =~ m%^[^/]% );
  37.     return @r;
  38.     } elsif ( $line =~ m%^([-a-zA-Z0-9_\./]+\.[a-zA-Z]+):(\d+):\s*\`(.+)\' was not declared% ) {
  39.     @r = ($1,$2,$3);
  40.     $r[0] = $currentdir . $r[0] if ( defined($currentdir) &&
  41.                      $r[0] =~ m%^[^/]% );
  42.     return @r;
  43.     } elsif ( $line =~ m%^g?make\[(\d+)\]: Entering directory \`(.*)\'% ) {
  44.     # make[1]: Entering directory `/home/agulbra/2x/src/ui'
  45.     my( $l, $c ) = ( $1, $2 );
  46.     $c =~ s-/?$-/-;
  47.     $dirs[$l] = $c;
  48.     $currentdir = $c;
  49.     print "$line\n";
  50.     } elsif ( $line =~ m%make\[(\d+)\]: Leaving directory \`.*\'$% ) {
  51.     # make[1]: Leaving directory `/home/agulbra/2x/src/ui'
  52.     $currentdir = defined( $dirs[$1 - 1] ) ? $dirs[$1 - 1] : "";
  53.     print "$line\n";
  54.     } elsif ( $line =~ m%^\S+:(?:\d+:)?\s+\S% ) {
  55.     # other compiler message - skip it
  56.     } else {
  57.     print "$line\n";
  58.     }
  59.  
  60.     return ();
  61. }
  62.  
  63.  
  64. #
  65. # this is the big array of globals and their replacements.  add stuff
  66. # at will.
  67. #
  68.  
  69. %globals =
  70. (
  71.  "Event_None" => "QEvent::None",
  72.  "Event_Timer" => "QEvent::Timer",
  73.  "Event_MouseButtonPress" => "QEvent::MouseButtonPress",
  74.  "Event_MouseButtonRelease" => "QEvent::MouseButtonRelease",
  75.  "Event_MouseButtonDblClick" => "QEvent::MouseButtonDblClick",
  76.  "Event_MouseMove" => "QEvent::MouseMove",
  77.  "Event_KeyPress" => "QEvent::KeyPress",
  78.  "Event_KeyRelease" => "QEvent::KeyRelease",
  79.  "Event_FocusIn" => "QEvent::FocusIn",
  80.  "Event_FocusOut" => "QEvent::FocusOut",
  81.  "Event_Enter" => "QEvent::Enter",
  82.  "Event_Leave" => "QEvent::Leave",
  83.  "Event_Paint" => "QEvent::Paint",
  84.  "Event_Move" => "QEvent::Move",
  85.  "Event_Resize" => "QEvent::Resize",
  86.  "Event_Create" => "QEvent::Create",
  87.  "Event_Destroy" => "QEvent::Destroy",
  88.  "Event_Show" => "QEvent::Show",
  89.  "Event_Hide" => "QEvent::Hide",
  90.  "Event_Close" => "QEvent::Close",
  91.  "Event_Quit" => "QEvent::Quit",
  92.  "Event_Accel" => "QEvent::Accel",
  93.  "Event_Clipboard" => "QEvent::Clipboard",
  94.  "Event_SockAct" => "QEvent::SockAct",
  95.  "Event_DragEnter" => "QEvent::DragEnter",
  96.  "Event_DragMove" => "QEvent::DragMove",
  97.  "Event_DragLeave" => "QEvent::DragLeave",
  98.  "Event_Drop" => "QEvent::Drop",
  99.  "Event_DragResponse" => "QEvent::DragResponse",
  100.  "Event_ChildInserted" => "QEvent::ChildInserted",
  101.  "Event_ChildRemoved" => "QEvent::ChildRemoved",
  102.  "Event_LayoutHint" => "QEvent::LayoutHint",
  103.  "Event_User" => "QEvent::User",
  104.  
  105.  "color0" => "Qt::color0",
  106.  "color1" => "Qt::color1",
  107.  "black" => "Qt::black",
  108.  "white" => "Qt::white",
  109.  "darkGray" => "Qt::darkGray",
  110.  "gray" => "Qt::gray",
  111.  "lightGray" => "Qt::lightGray",
  112.  "red" => "Qt::red",
  113.  "green" => "Qt::green",
  114.  "blue" => "Qt::blue",
  115.  "cyan" => "Qt::cyan",
  116.  "magenta" => "Qt::magenta",
  117.  "yellow" => "Qt::yellow",
  118.  "darkRed" => "Qt::darkRed",
  119.  "darkGreen" => "Qt::darkGreen",
  120.  "darkBlue" => "Qt::darkBlue",
  121.  "darkCyan" => "Qt::darkCyan",
  122.  "darkMagenta" => "Qt::darkMagenta",
  123.  "darkYellow" => "Qt::darkYellow",
  124.  
  125.  "AlignLeft" => "Qt::AlignLeft",
  126.  "AlignRight" => "Qt::AlignRight",
  127.  "AlignHCenter" => "Qt::AlignHCenter",
  128.  "AlignTop" => "Qt::AlignTop",
  129.  "AlignBottom" => "Qt::AlignBottom",
  130.  "AlignVCenter" => "Qt::AlignVCenter",
  131.  "AlignCenter" => "Qt::AlignCenter",
  132.  "SingleLine" => "Qt::SingleLine",
  133.  "DontClip" => "Qt::DontClip",
  134.  "ExpandTabs" => "Qt::ExpandTabs",
  135.  "ShowPrefix" => "Qt::ShowPrefix",
  136.  "WordBreak" => "Qt::WordBreak",
  137.  "DontPrint" => "Qt::DontPrint",
  138.  
  139.  "TransparentMode" => "Qt::TransparentMode",
  140.  "OpaqueMode" => "Qt::OpaqueMode",
  141.  
  142.  "PixelUnit" => "Qt::PixelUnit",
  143.  "LoMetricUnit" => "Qt::LoMetricUnit",
  144.  "HiMetricUnit" => "Qt::HiMetricUnit",
  145.  "LoEnglishUnit" => "Qt::LoEnglishUnit",
  146.  "HiEnglishUnit" => "Qt::HiEnglishUnit",
  147.  "TwipsUnit" => "Qt::TwipsUnit",
  148.  
  149.  "WindowsStyle" => "Qt::WindowsStyle",
  150.  "MotifStyle" => "Qt::MotifStyle",
  151.  
  152.  "Horizontal" => "Qt::Horizontal",
  153.  "Vertical" => "Qt::Vertical",
  154.  
  155.  "PenStyle" => "Qt::PenStyle",
  156.  "NoPen" => "Qt::NoPen",
  157.  "SolidLine" => "Qt::SolidLine",
  158.  "DashLine" => "Qt::DashLine",
  159.  "DotLine" => "Qt::DotLine",
  160.  "DashDotLine" => "Qt::DashDotLine",
  161.  "DashDotDotLine" => "Qt::DashDotDotLine",
  162.  
  163.  "BrushStyle" => "Qt::BrushStyle",
  164.  "NoBrush" => "Qt::NoBrush",
  165.  "SolidPattern" => "Qt::SolidPattern",
  166.  "Dense1Pattern" => "Qt::Dense1Pattern",
  167.  "Dense2Pattern" => "Qt::Dense2Pattern",
  168.  "Dense3Pattern" => "Qt::Dense3Pattern",
  169.  "Dense4Pattern" => "Qt::Dense4Pattern",
  170.  "Dense5Pattern" => "Qt::Dense5Pattern",
  171.  "Dense6Pattern" => "Qt::Dense6Pattern",
  172.  "Dense7Pattern" => "Qt::Dense7Pattern",
  173.  "HorPattern" => "Qt::HorPattern",
  174.  "VerPattern" => "Qt::VerPattern",
  175.  "CrossPattern" => "Qt::CrossPattern",
  176.  "BDiagPattern" => "Qt::BDiagPattern",
  177.  "FDiagPattern" => "Qt::FDiagPattern",
  178.  "DiagCrossPattern" => "Qt::DiagCrossPattern",
  179.  "CustomPattern" => "Qt::CustomPattern",
  180.  
  181.  "arrowCursor" => "Qt::arrowCursor",
  182.  "upArrowCursor" => "Qt::upArrowCursor",
  183.  "crossCursor" => "Qt::crossCursor",
  184.  "waitCursor" => "Qt::waitCursor",
  185.  "ibeamCursor" => "Qt::ibeamCursor",
  186.  "sizeVerCursor" => "Qt::sizeVerCursor",
  187.  "sizeHorCursor" => "Qt::sizeHorCursor",
  188.  "sizeBDiagCursor" => "Qt::sizeBDiagCursor",
  189.  "sizeFDiagCursor" => "Qt::sizeFDiagCursor",
  190.  "sizeAllCursor" => "Qt::sizeAllCursor",
  191.  "blankCursor" => "Qt::blankCursor",
  192.  "splitVCursor" => "Qt::splitVCursor",
  193.  "splitHCursor" => "Qt::splitHCursor",
  194.  "pointingHandCursor" => "Qt::pointingHandCursor"
  195. );
  196.  
  197. if ( defined( $ENV{"QTDIR"} ) &&
  198.      open( I, "< ". $ENV{"QTDIR"} . "/src/kernel/q1xcompatibility.h" ) ) {
  199.     while( <I> ) {
  200.     if ( /\#define\s+([a-zA-Z0-9_]+)\s+(\S+)/ ) {
  201.         if ( !defined( $globals{$1} ) ) {
  202.         $globals{$1} = $2;
  203.         } elsif ( $globals{$1} ne $2 ) {
  204.         #print "conflict: $1 is mapped to $2 and $globals{$1}\n";
  205.         }
  206.     }
  207.     }
  208.     close I;
  209. }
  210.  
  211. #
  212. # do the do
  213. #
  214.  
  215. while( <STDIN> ) {
  216.     @r = parseline($_);
  217.     next unless @r;
  218.     ($file, $line, $variable) = @r;
  219.     if ( defined( $variable ) && defined($globals{$variable}) ) {
  220.     if ( !defined($lastfile) || ($file ne $lastfile) ) {
  221.         $lastfile = undef if ( !$changes );
  222.         if ( defined( $lastfile ) ) {
  223.         open( O, "> $lastfile" ) ||
  224.           die "cannot write to $lastfile, stopped";
  225.         print "qt20fix: writing $lastfile (changes: $changes)\n";
  226.         print O @currentfile;
  227.         close O;
  228.         }
  229.         open( I, "< $file" ) || die "cannot read $file, stopped";
  230.         @currentfile = <I>;
  231.         close I;
  232.         $lastfile = $file;
  233.         $changes = 0;
  234.     }
  235.     next unless ( defined( $currentfile[$line-1] ) );
  236.     next unless ( $currentfile[$line-1] =~ /\b$variable\b/ );
  237.     if ( $currentfile[$line-1] =~ s/([^a-zA-Z0-9])::$variable\b/$1$globals{$variable}/ ||
  238.          $currentfile[$line-1] =~ s/([^a-zA-Z0-9:])$variable\b/$1$globals{$variable}/ ) {
  239.         print "$file:$line:replaced \`$variable\' with \`$globals{$variable}\'\n";
  240.         $changes++;
  241.         $totalchanges++
  242.     }
  243.     } elsif ( defined( $variable ) ) {
  244.     print "$file:$line: unknown undefined variable $variable\n";
  245.     }
  246. }
  247.  
  248. if ( defined( $changes) && $changes > 0 && defined( $lastfile ) ) {
  249.     open( O, "> $lastfile" ) ||
  250.       die "cannot write to $lastfile, stopped";
  251.     print "qt20fix: writing $lastfile (changes: $changes)\n";
  252.     print O @currentfile;
  253.     close O;
  254. }
  255.  
  256.  
  257. if ( defined( $totalchanges) && $totalchanges > 0 ) {
  258.     print "qt20fix: total changes: $totalchanges\nqt20fix: rerun recommended\n";
  259. }
  260.